/**
 * fileName:  ArgumentCostImpl.java
 * author:  Pitaya
 * Company:  Cloudland Studio
 * Createdate:  2014-6-7 上午12:45:15
 *
 * All rights Reserved, Designed By cloudland Copyright(C) 2010-2011
 *   
 * Modification  History:
 *     Date           Author        Version        
 * -------------------------------------------
 * 2014-6-7            Pitaya            1.0        
 *
 * Why & What is modified:
 * 1.0: 文件创建
 */
package org.cloudland.commercial.masterdata.handler.support;

import java.util.List;

import org.cloudland.commercial.masterdata.bean.ArgumentCostInfo;
import org.cloudland.commercial.masterdata.handler.ArgumentCostStore;
import org.cloudland.commercial.masterdata.store.entity.CostEntity;
import org.cloudland.commercial.masterdata.store.read.ArgumentCostReader;
import org.cloudland.commercial.masterdata.store.write.ArgumentCostWriter;

 /**
 * <pre> 
 * TODO 请充分描述该类提供的作用, 或与其他类会有关联的使用。
 * 使用 java.lang.Object#toString(), 或者 {@link java.lang.Character Character} 等标签
 * </pre>
 * @ClassName  ArgumentCostImpl
 * @author  Pitaya
 * @version  %I%, %G%
 * @see  
 * @since   JDK1.6
 *
 */
public class ArgumentCostImpl implements ArgumentCostStore {

	/**
	 * costReader 参数取值读取操作
	 */
	private ArgumentCostReader costReader;
	
	/**
	 * costWriter 参数取值增、删、改操作
	 */
	private ArgumentCostWriter costWriter;
	
	/**
	 * <pre>
	 * TODO 请充分描述该构造函数的作用，及其参数的作用。
	 * </pre>
	 *
	 * @param costReader
	 * @param costWriter   
	 */
	public ArgumentCostImpl(ArgumentCostWriter costWriter,
			ArgumentCostReader costReader) {
		this.costWriter = costWriter;
		this.costReader = costReader;
	}

	/**
	 * @return
	 */
	public ArgumentCostInfo createParamCost() {
		ArgumentCostInfo costInfo = new ArgumentCostBean(costWriter, costReader);
		return costInfo;
	}

	/**
	 * @return
	 */
	public ArgumentCostInfo[] findRootParamCost() {
		List<CostEntity> costList = costReader.findArgumentCostRoot();
		if(null == costList)
		{
			return null;
		}
		ArgumentCostInfo[] resultArray = new ArgumentCostInfo[costList.size()];
		for(int i = 0; i < costList.size(); i++)
		{
			resultArray[i] = new ArgumentCostBean(costList.get(i), costWriter, costReader);
		}
		return resultArray;
	}

	/**
	 * @param costId
	 * @return
	 */
	public ArgumentCostInfo queryParamCostInfo(String costId) {
		CostEntity entity = costReader.findCostById(costId);
		return new ArgumentCostBean(entity, costWriter, costReader);
	}

	/**
	 * 删除
	 * @param costId
	 * @return
	 */
	public Boolean delParamCost(String costId) {
		boolean flag = false;
		CostEntity entity = new CostEntity();
		entity.setCostId(costId);
		Integer rtn = costWriter.delArgumentCost(entity);
		if(rtn > 0){
			flag = true;
		}
		return flag;
	}

}
